import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 第十题
 * User: 姚东名
 * Date: 2024-11-16
 * Time: 10:31
 */
public class Demo5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        scanner.close();

        System.out.println(find(n, a));
    }

    public static int find(int n, int[] a) {
        int[] left = new int[n];
        int[] right = new int[n];

        // 计算从左到右的最长递增子序列长度
        for (int i = 0; i < n; i++) {
            left[i] = 1;
            for (int j = 0; j < i; j++) {
                if (a[j] < a[i]) {
                    left[i] = Math.max(left[i], left[j] + 1);
                }
            }
        }

        // 计算从右到左的最长递增子序列长度
        for (int i = n - 1; i >= 0; i--) {
            right[i] = 1;
            for (int j = n - 1; j > i; j--) {
                if (a[j] < a[i]) {
                    right[i] = Math.max(right[i], right[j] + 1);
                }
            }
        }

        // 找到最长的勾形子序列
        int maxLength = 0;
        for (int i = 0; i < n; i++) {
            // 勾形子序列长度为左侧递增序列长度 + 1（拐点） + 右侧递增序列长度
            maxLength = Math.max(maxLength, left[i] + right[i] - 1);
        }

        return maxLength;
    }
}
